package com.bluemobi.system.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.bluemobi.framework.base.impl.BaseServiceImpl;
import com.bluemobi.framework.cache.Cache;
import com.bluemobi.framework.constant.SystemConstant;
import com.bluemobi.system.service.SysDicService;
import com.bluemobi.system.vo.DicTypeVo;
import com.bluemobi.system.vo.DicVo;

/**
 * 数据字典service接口实现类
 *
 * @author zhangyong
 * @version 1.0
 * @Date 2016-4-7 15:07
 * @extends BaseServiceImpl
 * @implements SysDicService
 */
@Service
public class SysDicServiceImpl extends BaseServiceImpl implements SysDicService {

	@Resource
	public Cache cache;

	/**
	 * 获取所有数据字典分类
	 *
	 * @return List
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<DicTypeVo> getDicTypeList() throws Exception {
		try {
			if (null != cache.get(SystemConstant.SYS_DICTYPE_NAME)) {
				return (List<DicTypeVo>) cache.get(SystemConstant.SYS_DICTYPE_NAME);
			} else {
				Map<String, Object> map = new HashMap<>();
				map.put("dicType", SystemConstant.DEFAULT_DICID);
				return dbManage.selectListByCondition(map);
			}
		} catch (Exception e) {
			Map<String, Object> map = new HashMap<>();
			map.put("dicType", SystemConstant.DEFAULT_DICID);
			return dbManage.selectListByCondition(map);
		}
	}

	/**
	 * 获取所有数据字典
	 *
	 * @return List
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<DicVo> getDicCacheList() throws Exception {
		try {
			if (null != cache.get(SystemConstant.SYS_DICTYPE_NAME)) {
				return (List<DicVo>) cache.get(SystemConstant.SYS_DICTYPE_NAME);
			} else {
				Map<String, Object> map = new HashMap<>();
				map.put("dicType", SystemConstant.DEFAULT_DICID);
				map.put("state", SystemConstant.RETURN_STATUS_SUCCESS);
				return dbManage.selectListByCondition(map);
			}
		} catch (Exception e) {
			Map<String, Object> map = new HashMap<>();
			map.put("state", SystemConstant.RETURN_STATUS_SUCCESS);
			map.put("dicType", SystemConstant.DEFAULT_DICID);
			return dbManage.selectListByCondition(map);
		}
	}
}
